// NAVIGATOR.h : Declaration of the NAVIGATOR

#pragma once
#include "resource.h"       // main symbols
#include "DmhMemory.h"
#include "..\..\dmalgo.h"
#include "..\..\oledbdm.h"
#include "ALGORITHM.h"
#include "DmhVector.h"
#include "Hierarchies.h"

#include "Plugin.h"


// NAVIGATOR

class ATL_NO_VTABLE NAVIGATOR : 
	public DMHALLOC,
	public CComObjectRootEx<CComMultiThreadModel>,
	public CComCoClass<NAVIGATOR, &CLSID_NAVIGATOR>,
	public ISupportErrorInfo,
	public IDMAlgorithmNavigation
{
public:
	NAVIGATOR() : _viAttributeOutput(*this)
	{
		_palgorithm		= NULL;
		_bDMDimension	= false;
		_iIDNode		= (UINT) -1;
	}

DECLARE_REGISTRY_RESOURCEID(IDR_NAVIGATOR)


BEGIN_COM_MAP(NAVIGATOR)
	COM_INTERFACE_ENTRY(IDMAlgorithmNavigation)
	COM_INTERFACE_ENTRY(ISupportErrorInfo)
END_COM_MAP()

	HRESULT		Initialize(bool bDMDimension, ALGORITHM* palgorithm);

// ISupportsErrorInfo
	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

protected:

	  ALGORITHM*	_palgorithm;
	  bool		_bDMDimension;
	  VINT		_viAttributeOutput; // Output attributes
	  LRPHIERARCHY	_lrphierarchy;
	  ULONG		_iIDNode; 	// Current state of the navigator

public:


	// IDMDAGNavigation

	STDMETHOD (MoveToNextTree)(void);
	
	STDMETHOD (GetNodeID)(
		/* [out] */ DM_DAGNodeID *out_pNodeID);

	STDMETHOD (LocateNode)(
		/* [in] */ DM_DAGNodeID in_NodeID);

	STDMETHOD (ValidateNodeID)(
		/* [in] */ DM_DAGNodeID in_NodeID);
    
    STDMETHOD (GetParentCount)(
		/* [out] */ ULONG *out_pulParents);

    STDMETHOD (MoveToParent)(
		/* [in] */ ULONG in_ParentIndex);

	STDMETHOD (GetParentNodeID)(
		/* [in] */ ULONG in_ParentIndex,
		/* [out] */ DM_DAGNodeID *out_pNodeID);

    STDMETHOD (GetChildCount)(
		/* [out] */ ULONG *out_pulChilds);

    STDMETHOD (MoveToChild)(
		/* [in] */ ULONG in_ChildIndex);

    STDMETHOD (GetChildNodeID)(
		/* [in] */ ULONG			in_ChildIndex,
		/* [out] */ DM_DAGNodeID*	out_pNodeID);

    STDMETHOD (MoveToNextLeaf)(
		/* [in] */ DM_DAGNodeID in_ScopeNodeID);
    
    STDMETHOD (AddRefNodeID)(
		/* [in] */ DM_DAGNodeID in_NodeID);

    STDMETHOD (ReleaseNodeID)(
		/* [in] */ DM_DAGNodeID in_NodeID);

	// IDMAlgorithmNavigation

	STDMETHOD (GetNodeProperty)(
		/* [in] */ IDMContextServices*	in_pContext,
		/* [in] */ DM_NODE_PROP			in_PropID,
		/* [in] */ DMVariantPtr			io_pValue);
	
    STDMETHOD (GetNodeArrayProperty)(
		/* [in] */ IDMContextServices*	in_pContext,
		/* [in] */ DM_NODE_PROP			in_PropID,
		/* [out] */ ULONG*				out_pulArraySize,
		/* [out] */ void**				out_prgArrayBuffer);
    
    STDMETHOD (GetNodeUniqueName)(
		/* [in] */ IDMContextServices*	in_pContext,
		/* [out] */ DMString*			io_pstrUniqueName);

	STDMETHOD (GetNodeIDFromUniqueName)(
		/* [in] */ IDMContextServices*	in_pContext,
        /* [in] */ DMString*			in_pstrUniqueName,
        /* [out] */ DM_DAGNodeID*		out_pNodeID);

    STDMETHOD (GetUniqueNameFromNodeID)( 
        /* [in] */ IDMContextServices*	in_pContext,
        /* [in] */ DM_DAGNodeID			in_NodeID,
        /* [out] */ DMString*			out_pstrUniqueName);


};

OBJECT_ENTRY_AUTO(__uuidof(NAVIGATOR), NAVIGATOR)
